


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > NavigationTest</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.npc.ghost</a>
</div>

<h1>Coverage Summary for Class: NavigationTest (nl.tudelft.jpacman.npc.ghost)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">NavigationTest</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/10)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/57)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.npc.ghost;
&nbsp;
&nbsp;import com.google.common.collect.Lists;
&nbsp;import nl.tudelft.jpacman.board.Board;
&nbsp;import nl.tudelft.jpacman.board.BoardFactory;
&nbsp;import nl.tudelft.jpacman.board.Direction;
&nbsp;import nl.tudelft.jpacman.board.Square;
&nbsp;import nl.tudelft.jpacman.board.Unit;
&nbsp;import nl.tudelft.jpacman.level.LevelFactory;
&nbsp;import nl.tudelft.jpacman.level.MapParser;
&nbsp;import nl.tudelft.jpacman.level.Pellet;
&nbsp;import nl.tudelft.jpacman.npc.Ghost;
&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
&nbsp;import nl.tudelft.jpacman.sprite.PacManSprites;
&nbsp;import org.junit.jupiter.api.BeforeEach;
&nbsp;import org.junit.jupiter.api.Test;
&nbsp;
&nbsp;import java.io.IOException;
&nbsp;import java.io.InputStream;
&nbsp;import java.util.List;
&nbsp;
&nbsp;import static org.assertj.core.api.Assertions.assertThat;
&nbsp;import static org.mockito.Mockito.mock;
&nbsp;
&nbsp;/**
&nbsp; * Tests the various methods provided by the {@link Navigation} class.
&nbsp; *
&nbsp; * @author Jeroen Roosen
&nbsp; */
&nbsp;@SuppressWarnings({&quot;magicnumber&quot;, &quot;PMD.AvoidDuplicateLiterals&quot;})
<b class="nc">&nbsp;class NavigationTest {</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Map parser used to construct boards.
&nbsp;     */
&nbsp;    private MapParser parser;
&nbsp;
&nbsp;    /**
&nbsp;     * Set up the map parser.
&nbsp;     */
&nbsp;    @BeforeEach
&nbsp;    void setUp() {
<b class="nc">&nbsp;        PacManSprites sprites = new PacManSprites();</b>
<b class="nc">&nbsp;        LevelFactory levelFactory = new LevelFactory(</b>
&nbsp;            sprites,
&nbsp;            new GhostFactory(sprites),
<b class="nc">&nbsp;            mock(PointCalculator.class));</b>
<b class="nc">&nbsp;        parser = new MapParser(levelFactory, new BoardFactory(sprites));</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that the path to the same square is empty.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testShortestPathEmpty() {
<b class="nc">&nbsp;        Board b = parser.parseMap(Lists.newArrayList(&quot; &quot;)).getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(0, 0);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(0, 0);</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; path = Navigation</b>
<b class="nc">&nbsp;            .shortestPath(s1, s2, mock(Unit.class));</b>
<b class="nc">&nbsp;        assertThat(path).isEmpty();</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that if no path exists, the result is &lt;code&gt;null&lt;/code&gt;.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testNoShortestPath() {
<b class="nc">&nbsp;        Board b = parser</b>
<b class="nc">&nbsp;            .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# # #&quot;, &quot;#####&quot;))</b>
<b class="nc">&nbsp;            .getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(3, 1);</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; path = Navigation</b>
<b class="nc">&nbsp;            .shortestPath(s1, s2, mock(Unit.class));</b>
<b class="nc">&nbsp;        assertThat(path).isNull();</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that having no traveller ignores terrain.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testNoTraveller() {
<b class="nc">&nbsp;        Board b = parser</b>
<b class="nc">&nbsp;            .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# # #&quot;, &quot;#####&quot;))</b>
<b class="nc">&nbsp;            .getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(3, 1);</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; path = Navigation.shortestPath(s1, s2, null);</b>
<b class="nc">&nbsp;        assertThat(path).containsExactly(Direction.EAST, Direction.EAST);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Tests if the algorithm can find a path in a straight line.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testSimplePath() {
<b class="nc">&nbsp;        Board b = parser.parseMap(Lists.newArrayList(&quot;####&quot;, &quot;#  #&quot;, &quot;####&quot;))</b>
<b class="nc">&nbsp;            .getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(2, 1);</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; path = Navigation</b>
<b class="nc">&nbsp;            .shortestPath(s1, s2, mock(Unit.class));</b>
<b class="nc">&nbsp;        assertThat(path).containsExactly(Direction.EAST);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that the algorithm can find a path when it has to take corners.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testCornerPath() {
<b class="nc">&nbsp;        Board b = parser.parseMap(</b>
<b class="nc">&nbsp;            Lists.newArrayList(&quot;####&quot;, &quot;#  #&quot;, &quot;## #&quot;, &quot;####&quot;)).getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(2, 2);</b>
<b class="nc">&nbsp;        List&lt;Direction&gt; path = Navigation</b>
<b class="nc">&nbsp;            .shortestPath(s1, s2, mock(Unit.class));</b>
<b class="nc">&nbsp;        assertThat(path).containsExactly(Direction.EAST, Direction.SOUTH);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that the nearest object is detected.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testNearestUnit() {
<b class="nc">&nbsp;        Board b = parser</b>
<b class="nc">&nbsp;            .parseMap(Lists.newArrayList(&quot;#####&quot;, &quot;# ..#&quot;, &quot;#####&quot;))</b>
<b class="nc">&nbsp;            .getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;        Square s2 = b.squareAt(2, 1);</b>
<b class="nc">&nbsp;        Square result = Navigation.findNearest(Pellet.class, s1).getSquare();</b>
<b class="nc">&nbsp;        assertThat(result).isEqualTo(s2);</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that there is no such location if there is no nearest object.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testNoNearestUnit() {
<b class="nc">&nbsp;        Board b = parser.parseMap(Lists.newArrayList(&quot; &quot;)).getBoard();</b>
<b class="nc">&nbsp;        Square s1 = b.squareAt(0, 0);</b>
<b class="nc">&nbsp;        Unit unit = Navigation.findNearest(Pellet.class, s1);</b>
<b class="nc">&nbsp;        assertThat(unit).isNull();</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Verifies that there is ghost on the default board
&nbsp;     * next to cell [1, 1].
&nbsp;     *
&nbsp;     * @throws IOException if board reading fails.
&nbsp;     */
&nbsp;    @Test
&nbsp;    void testFullSizedLevel() throws IOException {
<b class="nc">&nbsp;        try (InputStream i = getClass().getResourceAsStream(&quot;/board.txt&quot;)) {</b>
<b class="nc">&nbsp;            Board b = parser.parseMap(i).getBoard();</b>
<b class="nc">&nbsp;            Square s1 = b.squareAt(1, 1);</b>
<b class="nc">&nbsp;            Unit unit = Navigation.findNearest(Ghost.class, s1);</b>
<b class="nc">&nbsp;            assertThat(unit).isNotNull();</b>
<b class="nc">&nbsp;        }</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-11 19:39</div>
</div>
</body>
</html>
